package chapter06.join;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class JoinMapper extends Mapper<LongWritable, Text, Text, JoinBean> {
    private final JoinBean valueOut = new JoinBean();
    private final Text keyOut = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields = line.split("\t");

        valueOut.setO_id(fields[0]);
        valueOut.setP_id(fields[1]);
        valueOut.setP_amount(Integer.parseInt(fields[2]));
        valueOut.setP_name("");
        valueOut.setFlag("order");
        keyOut.set(fields[1]);

        context.write(keyOut, valueOut);
    }
}
